<template>
    <swiper :options="swiperOption">
        <swiper-slide v-for="(page, index) in pages" :key="index">
            <div class="icons">
                <div class="icon" v-for="item in page" :key="item.id">
                    <div class="icon-img">
                        <img :src="item.imgUrl" />
                    </div>
                    <p>{{ item.desc }}</p>
                </div>
            </div>
        </swiper-slide>
    </swiper>
</template>

<script>
export default {
    name: "HomeIcons",
    props: {
        list:Array
    },
    data() {
        return {
            swiperOption: {
                autoplay:false
            }
        }
    },
    computed: {
        pages() {
            const pages = [];
            this.list.forEach((item, index) => {
                const page = Math.floor(index / 8);
                if (!pages[page]) {
                    pages[page] = [];
                }
                pages[page].push(item);
            });
            return pages;
        },
    },
};
</script>

<style scoped>
.icons {
    display: flex;
    flex-wrap: wrap;
    padding: .1rem 0;
}
.icon {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 25%;
    box-sizing: border-box;
    margin: .1rem 0;
}
.icon-img img {
    display: block;
    width: 1rem;
}
.icon p {
    width: 100%;
    text-align: center;
    font-size: 0.24rem;
    color: #333;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    margin-top: .1rem;
}
</style>